
#include <bits/stdc++.h>
using namespace std;
namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin


#define cout Fastio::cout


}
#include<bits/stdc++.h>
using namespace std;
long long sum[200005];
struct f{int fa,dfn,dep,son,siz,top;}tr[200005];
struct f1{int x,k;};
vector<f1>s[200005];
int id[200005];
void dfs(int p,int fa){
	tr[p].fa=fa;tr[p].siz=1;tr[p].dep=tr[fa].dep+1;
	for(int i=0;i<s[p].size();i++){
		int y=s[p][i].x,k=s[p][i].k;
		if(y==fa) continue;sum[y]=sum[p]+k;dfs(y,p);tr[p].siz+=tr[y].siz;
		if(tr[tr[p].son].siz<tr[y].siz) tr[p].son=y;
	}
}int cnt;
void dfs1(int p,int top){
	tr[p].top=top;tr[p].dfn=++cnt;id[cnt]=p;
	if(tr[p].son) dfs1(tr[p].son,top);
	for(int i=0;i<s[p].size();i++){
		int y=s[p][i].x;if(y==tr[p].fa||y==tr[p].son) continue;
		dfs1(y,y);
	}
}
int lca(int x,int y){
	while(tr[x].top!=tr[y].top){
		if(tr[tr[x].top].dep<tr[tr[y].top].dep) swap(x,y);
		x=tr[tr[x].top].fa;
	}
	if(tr[x].dep<tr[y].dep)return x;
	return y;
}
#define mid ((t[p].l+t[p].r)>>1)
struct f3{int l,r,ma,mi;}t[200005*4];
void wei(f3 &x,f3 y,f3 z){
	if(tr[y.ma].dfn>tr[z.ma].dfn) x.ma=y.ma;
	else x.ma=z.ma;
	if(tr[y.mi].dfn<tr[z.mi].dfn) x.mi=y.mi;
	else x.mi=z.mi;
}
void jianshu(int p,int l,int r){
	t[p].l=l,t[p].r=r;
	if(l==r){t[p].ma=l,t[p].mi=l;return;}
	jianshu(p*2,l,mid),jianshu(p*2+1,mid+1,r);
	wei(t[p],t[p*2],t[p*2+1]);
}
f3 cha(int p,int l,int r){
	if(t[p].l>=l&&t[p].r<=r) return t[p];
	if(r<=mid) return cha(p*2,l,r);
	if(l>mid) return cha(p*2+1,l,r);
	f3 ans;wei(ans,cha(p*2,l,r),cha(p*2+1,l,r));
	return ans;
}

#define ls tree[p].ch[0]
#define rs tree[p].ch[1]
struct f4{int ch[2],sum;}tree[200005*55];
int cn=0;
void wei1(int p){tree[p].sum=tree[ls].sum+tree[rs].sum;}
void add(int &p,int ps,int l,int r,int k){
	p=++cn;tree[p]=tree[ps];
	if(l==r){tree[p].sum++;return;}
	int mi=(l+r)/2;
	if(k<=mi) add(ls,tree[ps].ch[0],l,mi,k);
	else add(rs,tree[ps].ch[1],mi+1,r,k);
	wei1(p);
}
int chaxun(int p,int ps,int l,int r,int k){
	if(!p) return 0;
	if(l==r){if(tree[p].sum-tree[ps].sum==0||l>k) return 0;return l;}
	int mi=(l+r)/2;
	if(k>mi){
		int op=0;
		if(tree[rs].sum-tree[tree[ps].ch[1]].sum>0){
			op=chaxun(rs,tree[ps].ch[1],mi+1,r,k);
		}
		if(!op) op=chaxun(ls,tree[ps].ch[0],l,mi,k);
		return op;
	}
	else return chaxun(ls,tree[ps].ch[0],l,mi,k);
}
int chaxun1(int p,int ps,int l,int r,int k){
	if(!p) return 0;
	if(l==r){if(tree[p].sum-tree[ps].sum==0||l<k) return 0;return l;}
	int mi=(l+r)/2;
	if(k<mi){
		int op=0;
		if(tree[ls].sum-tree[tree[ps].ch[0]].sum>0){
			op=chaxun1(ls,tree[ps].ch[0],l,mi,k);
		}
		if(!op) op=chaxun1(rs,tree[ps].ch[1],mi+1,r,k);
		return op;
	}
	else return chaxun1(rs,tree[ps].ch[1],mi+1,r,k);
}
int root[200005];
signed main(){
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	int n,q;cin>>n>>q;
	for(int i=1;i<n;i++){
		int x,y,k;cin>>x>>y>>k;
		s[x].push_back(f1{y,k});
		s[y].push_back(f1{x,k});
	}	
	dfs(1,0),dfs1(1,1);
	jianshu(1,1,n);
	
	for(int i=1;i<=n;i++){add(root[i],root[i-1],1,n,tr[i].dfn);}
	long long las=0;
	while(q--){
		long long p,l,r;cin>>p>>l>>r;p=(p^las),l=(l^las),r=(r^las);
		f3 op=cha(1,l,r);
		int la=lca(op.mi,op.ma);
		int ll=lca(la,p);
		if(ll==p){las=sum[la]-sum[p];}
		else{
			int pr=chaxun(root[r],root[l-1],1,n,tr[p].dfn),nt=chaxun1(root[r],root[l-1],1,n,tr[p].dfn);
			if(pr)pr=lca(id[pr],p);if(nt)nt=lca(id[nt],p);
			if(nt==p){
				las=0;
			}
			else{
				if(tr[pr].dep<tr[nt].dep) pr=nt;
				las=sum[p]-sum[pr];
				if(lca(la,p)!=la) las=las+sum[la]-sum[ll];
			}
		}
		cout<<las<<'\n';
	}
	return 0;
}
